package itcast.shops.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import itcast.domain.ShopsBean;
import itcast.service.ShopsService;
import itcast.service.ShopsServiceimpl;


/**
 * Servlet implementation class shopindexServlet
 */
@WebServlet("/shopindexServlet")
public class ShopindexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShopindexServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			this.doPost(request, response);
			
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			//1、设置编码shop
			request.setCharacterEncoding("utf-8");//解决保存文件乱码问题
			response.setCharacterEncoding("utf-8");//解决转出文件乱码问题
			//2、执行service层查询返回一个list集合对象
			ShopsService service=new ShopsServiceimpl();
			List<ShopsBean> sBeans=service.findallshops();
			System.out.println(sBeans);
			//3、存储到request中
			request.setAttribute("shops", sBeans);
			//4、转发到显示页面
			request.getRequestDispatcher("shopindex.jsp").forward(request, response);
	}

}
